package com.joplus.housekeeper.ui.view.dialog;


import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.joplus.housekeeper.R;
import com.joplus.housekeeper.utils.StringUtils;

/**
 * Created by zisheng on 2017/8/14.
 */

public class IosDialog {

    private final TextView tv_title;
    private final TextView tv_message;
    private final TextView bt_right;
    private final TextView bt_left;
    private final Dialog dialog;

    public IosDialog(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_ios, null);
        dialog = new Dialog(context, R.style.background_dialog);
        dialog.setContentView(view);

        dialog.setCanceledOnTouchOutside(false);

        tv_title = (TextView) view.findViewById(R.id.tv_title);
        tv_message = (TextView) view.findViewById(R.id.tv_message);
        bt_left = (TextView) view.findViewById(R.id.bt_left);
        bt_right = (TextView) view.findViewById(R.id.bt_right);
        bt_left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (leftClick != null) {
                    leftClick.left();
                }
            }
        });

        bt_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (rightClick != null) {
                    rightClick.right();
                }
            }
        });
    }

    public void setTitle(String title) {
        StringUtils.setText(tv_title, title);
    }

    public void setMessage(String message) {
        StringUtils.setText(tv_message, message);
    }

    public void setLeftClick(String leftContent, LeftClick leftClick) {
        this.leftClick = leftClick;
        StringUtils.setText(bt_left, leftContent);
    }

    LeftClick leftClick;
    rightClick rightClick;

    public void setRightClick(String rightContent, rightClick rightClick) {
        this.rightClick = rightClick;
        StringUtils.setText(bt_right, rightContent);
    }

    public interface LeftClick {
        void left();
    }

    public interface rightClick {
        void right();
    }

    public void show() {
        dialog.show();
    }

    public void dismiss() {
        dialog.dismiss();
    }
}
